
package com.e885.sample.service;

import java.util.ArrayList;
import java.util.List;

import com.e885.hibernate.HibernateSessionFactory;
import com.e885.log.E885Logger;
import com.e885.sample.exception.QueryException;
import com.e885.sample.model.bean.County;
import com.e885.sample.model.dao.CountyDAO;
import com.e885.sample.view.bean.common.ComboBoxBean;
import com.e885.service.CommonService;

/**
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class CountyService extends CommonService
{
	/**
	 * 取得所有的鄉鎮市
	 * 
	 * @return
	 * @throws QueryException
	 */
	public static List< ComboBoxBean > getAllCounty() throws QueryException
	{
		E885Logger.serviceLog.info( "取得所有縣市資料" );
		
		try
		{
			List< ComboBoxBean > comboBoxBeanList = new ArrayList< ComboBoxBean >();

			List< County > countyList = new CountyDAO().findAllCounty();

			int size = countyList.size();
			for( int i = 0; i < size; i++ )
			{
				County county = countyList.get( i );

				comboBoxBeanList.add( new ComboBoxBean( county.getId(), county.getName() ) );
			}

			return comboBoxBeanList;
		}
		catch( RuntimeException e )
		{
			e.printStackTrace();
			
			E885Logger.serviceLog.error( "無法取得所有縣市資料" );
			
			throw new QueryException( "無法取得所有縣市資料" );
		}
		finally
		{
			HibernateSessionFactory.closeSession();
		}
	}
}
